package edu.ciee.tz.dao;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.stereotype.Component;

import edu.ciee.tz.model.Zhunzai;

@Component("zhunzaiDao")
public class ZhunzaiDAO {

	public List<Zhunzai> search(Zhunzai z) throws Exception {

		String query = "where 1=1";

		if (z.getId() != 0) 
			query = query + " and id like '%" + z.getId() + "%'";// this.getID()
		if (z.getZhunzai_time() != null) 
			query = query + " and zhunzai_time like '%" + z.getZhunzai_time() + "%'"; // this.getName()
		if (z.getFz_person()!=null&&z.getFz_person().getId()!= 0) 
			query = query + " and fz_person like '%" + z.getFz_person().getId()+ "%'";// this.getID()
		@SuppressWarnings("unchecked")
		List<Zhunzai> zhunzai_list = hibernateTemplate.find("from Zhunzai u "+ query);

		return zhunzai_list;
	}

	public void insert(Zhunzai z) throws Exception {
		this.getHibernateTemplate().save(z);
	}

	public void delete(Zhunzai z) throws Exception {
		this.getHibernateTemplate().delete(z);

	}

	public void update(Zhunzai z) throws Exception {
		this.getHibernateTemplate().update(z);
	}

	private HibernateTemplate hibernateTemplate;

	public HibernateTemplate getHibernateTemplate() {
		return hibernateTemplate;
	}

	@Resource
	public void setHibernateTemplate(HibernateTemplate hibernateTemplate) {
		this.hibernateTemplate = hibernateTemplate;
	}
}
